* Open a log

log using "/Users/jaakko/Documents/PA_replication_package/log_De_Magalhaes_et_al.smcl", replace // NB. REPLACE THIS WITH THE CORRECT DIRECTORY

********************************************************************************

clear all

********************************************************************************
********************************************************************************
**** When Can We Trust Regression Discontinuity Design Estimates from Close ****
*************** Elections? Evidence from Experimental Benchmarks ***************
********************************************************************************
********************************************************************************

* This is the master do file for replicating the tables and figures in
* De Magalhaes et al. (Political Analysis).

********************************************************************************

* Install required packages

ssc install rdrobust, replace
ssc install parmest, replace
ssc install estout, replace
ssc install rdmse, replace
ssc install rddensity, replace
ssc install addplot, replace
ssc install coefplot, replace

net from http://www.stata.com
net cd users
net cd vwiggins
net install grc1leg

* You should also install DCdensity following instructions available here:
* https://eml.berkeley.edu/~jmccrary/DCdensity/ (accessed August 22, 2024).

********************************************************************************

* Globals used in the analyses

global dir "/Users/jaakko/Documents/PA_replication_package" // NB. REPLACE THIS WITH YOUR WORKING DIRECTORY!
global tab "ci(%9.3f) b(%9.3f) scalars(h_l b_l N_h_l N_h_r) sfmt(%9.2f %9.2f %9.0g %9.0g) nogaps star(* 0.05 ** 0.01) mtitles brackets"

********************************************************************************

* Run the do files producing the analyses in the main text

do "$dir/code/Figure_1.do" // Figure 1

do "$dir/code/Table_1.do" // Table 1

********************************************************************************

* Run the do files producing the analyses in the online appendices

* Online Appendix B

do "$dir/code/Table_OA2.do" // Table OA2

do "$dir/code/Figure_OA2.do" // Figure OA2

* Online Appendix C

do "$dir/code/Table_OA3.do" // Table OA3

do "$dir/code/Table_OA4.do" // Table OA4

do "$dir/code/Figure_OA3.do" // Figure OA3

do "$dir/code/Figure_OA4.do" // Figure OA4

do "$dir/code/Table_OA5.do" // Table OA5

do "$dir/code/Table_OA6.do" // Table OA6

do "$dir/code/Table_OA7.do" // Table OA7

do "$dir/code/Table_OA8.do" // Table OA7

do "$dir/code/Table_OA9.do" // Table OA9

do "$dir/code/Table_OA10.do" // Table OA10

do "$dir/code/Table_OA11.do" // Table OA11

do "$dir/code/Table_OA12.do" // Table OA12

* Online Appendix D

do "$dir/code/Figure_OA5.do" // Figure OA5

do "$dir/code/Figure_OA6.do" // Figure OA6

do "$dir/code/Table_OA13.do" // Table OA13

do "$dir/code/Table_OA14.do" // Table OA14

do "$dir/code/Figure_OA7.do" // Figure OA7

do "$dir/code/Table_OA15.do" // Table OA15 -- NB. This file only produces the numbers; the table is then generated manually.

********************************************************************************

* Remove the files in the temp folder

// NB. This only works on Mac -- for a solution for Windows, see below.

cd $dir/temp

shell rm *.dta
shell rm *.gph

/*
To remove the files on Windows, you can run the following lines of code:

cd $dir/temp

!del *.dta
!del *.gph
*/

********************************************************************************

* Close the log

log close
